// Cities and States S 
#include<iostream>
#include<unordered_map>
using namespace std;
unordered_map<string,int> map;
int main()
{
	int n,ret = 0;
	cin >> n;
	while(n--)
	{
		string a,b;
		cin >> a >> b;
		a = a.substr(0,2);
		if(a == b) continue;
		ret += map[a + b];
		map[b + a]++;
	}
	cout << ret << endl;
	return 0;
}
